package gvo.util;



import gvo.amazon.AmazonEntry;
import gvo.basicDatatypes.AutorenDat;
import gvo.basicDatatypes.BuchDat;
import gvo.basicDatatypes.StichwortDat;
import gvo.importWindow.SearchResult;
import gvo.rero.MARC_Entry;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

public class ListColorRenderer extends DefaultListCellRenderer {
	private static final Color NORMAL = Color.BLACK;
	private static final Color VORHANDEN = Color.MAGENTA;
	private static final Color MULTIPLE = Color.BLUE;
	private static final Color NEU = Color.RED;
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
		if (value instanceof BuchDat) {
			BuchDat bu = (BuchDat)value;
			if(bu.isVerified){
				if(bu.isInDB){
					setForeground(VORHANDEN);
				} else {
					setForeground(NEU);
				}
			} else {
				setForeground(NORMAL);
			}
		} else if (value instanceof StichwortDat) {
			StichwortDat stw = (StichwortDat)value;
			if(stw.isVerified){
				if(stw.isInDB){
					setForeground(VORHANDEN);
				} else {
					setForeground(NEU);
				}
			} else {
				setForeground(NORMAL);
			}
		} else if (value instanceof AutorenDat) {
			AutorenDat au = (AutorenDat)value;
			if(au.isVerified){
				if(au.isInDB){
					if(au.multiple){
						setForeground(MULTIPLE);
					} else {
						setForeground(VORHANDEN);
					}
					
				} else {
					setForeground(NEU);
				}
			} else {
				setForeground(NORMAL);
			}
		} else if(value instanceof SearchResult){
			SearchResult re = (SearchResult)value;
			if (re.rEntry instanceof MARC_Entry){
				if(re.getMARC_Entry().gvoall.buch.isVerified){
					if(re.getMARC_Entry().gvoall.buch.isInDB){
						setForeground(VORHANDEN);
					} else {
						setForeground(NORMAL);
					}
				} else {
					setForeground(NORMAL);
				}
			} else if (re.rEntry instanceof AmazonEntry){
				if(re.getAmazonEntry().gvoall.buch.isVerified){
					if(re.getAmazonEntry().gvoall.buch.isInDB){
						setForeground(VORHANDEN);
					} else {
						setForeground(NORMAL);
					}
				} else {
					setForeground(NORMAL);
				}
			}
			
		}
		
		return this;
	}
}
